//
//  CGFloat+Extension.swift
//  Sevengrass
//
//  Created by Syrena on 2017/12/11.
//  Copyright © 2017年 Syrena. All rights reserved.
//

import Foundation
import Eureka

let priceFormatter = DecimalFormatter()

extension UInt {
    var int: Int {
        return Int(self)
    }
}

extension Int {

    // MARK: - 价格格式化
    var priceFormat: String {
        return priceFormatter.string(for: self)!
    }

    var adaption: CGFloat {
        return CGFloat(self) * adaptionX
    }

    //稍微加粗的字体
    var mediumFont: UIFont {
        return UIFont.systemFont(ofSize: self.cgFloat, weight: .medium)
    }

    //保留两位小数
    var string2f: String {
        return String(format: "%.2f", self)
    }

    ///格式化数字
    var formatNum: String {
        guard self < 10000 else {
            return self.string
        }
        return (self.double / 10000.0).string2f + "万"
    }

    var font: UIFont {

        return UIFont.systemFont(ofSize: CGFloat(self))
    }

    var boldFont: UIFont {
        return UIFont.boldSystemFont(ofSize: CGFloat(self))
    }

    var uInt: UInt {
        return UInt(self)
    }

    var int32: Int32 {
        return Int32(self)
    }

    var size: CGSize {
        return CGSize(width: self, height: self)
    }

    var edge: UIEdgeInsets {
        let num = self.cgFloat
        return UIEdgeInsets.init(top: num, left: num, bottom: num, right: num)
    }
}

extension Double {

    // MARK: - 价格格式化
    var priceFormat: String {
        return priceFormatter.string(for: self)!
    }

    var adaption: CGFloat {
        return CGFloat(self) * adaptionX
    }

    var string2f: String {
        return String(format: "%.2f", self)
    }
    var size: CGSize {
        return CGSize(width: self, height: self)
    }
    var edge: UIEdgeInsets {
        let num = self.cgFloat
        return UIEdgeInsets.init(top: num, left: num, bottom: num, right: num)
    }
}

extension Float {

    var adaption: CGFloat {
        return CGFloat(self) * adaptionX
    }

    var string2f: String {
        return String(format: "%.2f", self)
    }
    var edge: UIEdgeInsets {
        let num = self.cgFloat
        return UIEdgeInsets.init(top: num, left: num, bottom: num, right: num)
    }



}

extension CGFloat {

    // MARK: - 价格格式化
    var priceFormat: String {
        return priceFormatter.string(for: self)!
    }

    var adaption: CGFloat {
        return CGFloat(self) * adaptionX
    }

    var string2f: String {
        return String(format: "%.2f", self)
    }

    var size: CGSize {
        return CGSize(width: self, height: self)
    }

    var edge: UIEdgeInsets {
        return UIEdgeInsets.init(top: self, left: self, bottom: self, right: self)
    }
}
